import Vue from "vue";
import VueRouter from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
import storage from "../utils/storage";
import store from "../store";
import { message } from "../plugins/ElementUI";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/layout",
  },
  {
    path: "/layout",
    name: "layout",
    component: () => import("@/layout"),
    children: [],
  },
];

NProgress.configure({ showSpinner: false });

const router = new VueRouter({
  mode: "history",
  base: "/",
  routes,
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

router.beforeEach(async (to, from, next) => {
  store.commit("setLoading", true);
  NProgress.start();

  next();
});

router.afterEach(() => {
  NProgress.done();
  setTimeout(() => {
    store.commit("setLoading", false);
  }, 500);
});
export default router;
